package cn.com.yiqi.wsc.service.check.impl;

import cn.com.yiqi.wsc.common.Result;
import cn.com.yiqi.wsc.common.ResultStatusEnum;
import cn.com.yiqi.wsc.dao.check.CheckDao;
import cn.com.yiqi.wsc.entity.check.Check;
import cn.com.yiqi.wsc.service.check.CheckService;
import cn.com.yiqi.wsc.service.user.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @author 杨贵森
 * @ClassName:CheckServiceImpl
 * @Title: CheckServiceImpl
 * @Description: TODO
 * @date 2017/3/23
 */
@Service
public class CheckServiceImpl implements CheckService {

    @Autowired
    CheckDao checkDao;
    @Autowired
    UserService userService;
    @Override
    @Transactional
    public Result insertCheck(Check check) {
        check.setInsertUserId(userService.getCurrentUserId());
        Result result = new Result();
        result.setStatus(ResultStatusEnum.操作成功.getCode());
        checkDao.insert(check);
        return result;
    }

    @Override
    public Result selectOneCheck(Check check) {
        Result result = new Result();
        result.setStatus(ResultStatusEnum.操作成功.getCode());
        Check check1 = checkDao.getOneCheck(check);
        if(check1!=null){
            String [] desc= check1.getCheckDesc().split(",");
            List<String> checkDescList= new ArrayList<>(Arrays.asList(desc));
            check1.setDescList(checkDescList);
            result.putData("selectCheck",check1);
            return result;
        }
        result.putData("id",check.getContentId());
        return result;
    }
}
